﻿using BLP2API;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using SERFLITEMAX20;
using SERFLITEMAX20.SocketLib;
using SFmpqapi;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.Data.Linq;

namespace SERFLITEMAX20.Viewer
{

    public class frmRadar : Form
    {
        private SortedList<long, clsAlert> alertList = new SortedList<long, clsAlert>();
        private Hashtable areas = new Hashtable();
        private IContainer components = null;
        private Device device = null;
        private string filterName = "";
        private ViewObject focusObject = null;
        private Microsoft.DirectX.Direct3D.Font font;
        private bool hideName = false;
        private float mapSize = 34133.33f;
        private bool mbool = true;
        private Client mClient = null;
        private long mFocusGuid = 0L;
        private frmStatus mFormStatus = null;
        private bool mHasStarted = false;
        private List<clsMinimap> minimapCache = new List<clsMinimap>();
        private ViewMain mSender = new ViewMain();
        private Thread mThread = null;
        private FormWindowState previouseFormWindowState = FormWindowState.Normal;
        private float scale = 2f;
        public clsSettings settings;
        private TextBox tbInstructions;
        private float tileSize = 533.3333f;
        private int toggleViewMask = 0xfff;
        private VertexBuffer vbMine = null;
        private VertexBuffer vbMinimap = null;
        private VertexBuffer vbMonster = null;
        private VertexBuffer vbObject = null;
        private VertexBuffer vbPlayer = null;
        private VertexBuffer vbWeed = null;
        private bool wowactive = false;

        public frmRadar()
        {
            this.InitializeComponent();
            this.InitializeGraphics();
        }

        public void BuildAreas()
        {
            int hMPQ = 0;
            int hFile = 0;
            int lpFileSizeHigh = 0;
            int lpNumberOfBytesRead = 0;
            this.areas.Clear();
            if (SFmpq.SFileOpenArchive(@".\minimap.MPQ", 0, 0, ref hMPQ) == 1)
            {
                if (SFmpq.SFileOpenFileEx(hMPQ, "md5translate.trs", 0, ref hFile) == 1)
                {
                    lpFileSizeHigh = SFmpq.SFileGetFileSize(hFile, ref lpFileSizeHigh);
                    byte[] lpBuffer = new byte[lpFileSizeHigh];
                    if (SFmpq.SFileReadFile(hFile, lpBuffer, (uint)lpFileSizeHigh, ref lpNumberOfBytesRead, IntPtr.Zero) == 1)
                    {
                        this.BuildMinimapList(lpBuffer);
                    }
                    SFmpq.SFileCloseFile(hFile);
                }
                SFmpq.SFileCloseArchive(hMPQ);
            }
        }

        private void BuildMinimapList(byte[] md5list)
        {
            MemoryStream stream = new MemoryStream(md5list);
            StreamReader reader = new StreamReader(stream);
            Regex regex = new Regex(@"^.[^\\]+\\[a-z,A-Z]+([0-9][0-9])_([0-9][0-9])\.blp[\t, ]+(.+)$");
            clsArea area = null;
            while (reader.Peek() != -1)
            {
                int num2;
                int num3;
                string input = reader.ReadLine();
                if (input.StartsWith("dir: "))
                {
                    if (area != null)
                    {
                        int num = 0;
                        num2 = 0;
                        while (num2 < 0x40)
                        {
                            num3 = 0;
                            while (num3 < 0x40)
                            {
                                if (area.minimaps[num2, num3] != null)
                                {
                                    num++;
                                }
                                num3++;
                            }
                            num2++;
                        }
                    }
                    if (input.IndexOf(@"\") == -1)
                    {
                        area = new clsArea();
                        area.area = input.Remove(0, 5);
                        this.areas.Add(area.area, area);
                    }
                    else
                    {
                        area = null;
                    }
                }
                else if (area != null)
                {
                    Match match = regex.Match(input);
                    if (match.Success)
                    {
                        num2 = int.Parse(match.Groups[1].Value);
                        num3 = int.Parse(match.Groups[2].Value);
                        area.minimaps[num2, num3] = new clsMinimap();
                        area.minimaps[num2, num3].filename = match.Groups[3].Value;
                    }
                    else
                    {
                        Debug.WriteLine("no match " + input);
                    }
                }
            }
        }

        private void CalcToggleView(ToggleView pToggleView)
        {
            if (!this.IsToggleView(pToggleView))
            {
                this.toggleViewMask |= (int)pToggleView;
            }
            else
            {
                this.toggleViewMask &= ~(int)pToggleView;
            }
        }

        private Microsoft.DirectX.Vector3 ComputeNormal(Microsoft.DirectX.Vector3 v1, Microsoft.DirectX.Vector3 v2, Microsoft.DirectX.Vector3 v3)
        {
            return Microsoft.DirectX.Vector3.Normalize(Microsoft.DirectX.Vector3.Cross(Microsoft.DirectX.Vector3.Subtract(v2, v1), Microsoft.DirectX.Vector3.Subtract(v3, v1)));
        }

        private void ConnectClient()
        {
            if (this.mClient != null)
            {
                this.mClient.Dispose();
                this.mClient.UpdateEvent -= new Client.OnUpdateEvent(this.OnUpdate);
                this.mClient.ErrorEvent -= new Client.OnErrorEvent(this.OnUpdateStatus);
            }
            this.mClient = new Client();
            this.mClient.address = this.settings.Server;
            this.mClient.port = int.Parse(this.settings.Port);
            this.mClient.UpdateEvent += new Client.OnUpdateEvent(this.OnUpdate);
            this.mClient.ErrorEvent += new Client.OnErrorEvent(this.OnUpdateStatus);
            this.mClient.Start();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void DrawMinimap()
        {
            float num = ((this.mapSize / 2f) - this.focusObject.x) + this.tileSize;
            float num2 = ((this.mapSize / 2f) - this.focusObject.y) + this.tileSize;
            int num3 = ((int)(num / this.tileSize)) - 1;
            int num4 = ((int)(num2 / this.tileSize)) - 1;

            this.minimapCache.ForEach(t => t.cache = false);

            string mapName = this.mSender.MapName;
            for (int i = num3 - this.settings.MinimapRadius; i <= (num3 + this.settings.MinimapRadius); i++)
            {
                for (int j = num4 - this.settings.MinimapRadius; j <= (num4 + this.settings.MinimapRadius); j++)
                {
                    var current = this.LoadMinimap(i, j, mapName);
                    if (current != null)
                    {
                        current.cache = true;
                        if (current.texture != null)
                        {
                            float x = -((i * this.tileSize) - (this.mapSize / 2f)) - (this.tileSize / 2f);
                            float y = -((j * this.tileSize) - (this.mapSize / 2f)) - (this.tileSize / 2f);
                            if (current.dxt1)
                            {
                                this.device.Transform.World = (Microsoft.DirectX.Matrix.RotationX(3.141592f) * Microsoft.DirectX.Matrix.RotationY(3.141592f)) * Microsoft.DirectX.Matrix.Translation(x, y, -1000f);
                            }
                            else
                            {
                                this.device.Transform.World = Microsoft.DirectX.Matrix.RotationY(3.141592f) * Microsoft.DirectX.Matrix.Translation(x, y, -1000f);
                            }
                            this.device.SetTexture(0, current.texture);
                            this.device.TextureState[0].ColorOperation = TextureOperation.Modulate;
                            this.device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
                            this.device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
                            this.device.TextureState[0].AlphaOperation = TextureOperation.Disable;
                            this.device.VertexFormat = VertexFormats.Texture1 | VertexFormats.PositionNormal;
                            this.device.SetStreamSource(0, this.vbMinimap, 0);
                            this.device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
                        }
                    }
                }
            }
            foreach (clsMinimap minimap in this.minimapCache)
            {
                if (!minimap.cache && (minimap.texture != null))
                {
                    minimap.texture.Dispose();
                    minimap.texture = null;
                }
            }
        }

        private void frmMain_Closing(object sender, CancelEventArgs e)
        {
            this.settings.FormX = base.Left;
            this.settings.FormY = base.Top;
            this.settings.FormWidth = base.Width;
            this.settings.FormHeight = base.Height;
            XmlTextWriter writer = new XmlTextWriter("SERFLITEMAX20.Viewer.xml", Encoding.ASCII);
            new XmlSerializer(this.settings.GetType()).Serialize((XmlWriter)writer, this.settings);
            writer.Close();
        }

        private void frmMain_DoubleClick(object sender, EventArgs e)
        {
            this.mbool = !this.mbool;
        }

        private void frmMain_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && (e.KeyCode == Keys.F))
            {
                base.TopMost = false;
                frmFind find = new frmFind();
                string filterName = this.filterName;
                if (find.View(ref filterName) == DialogResult.OK)
                {
                    this.filterName = filterName;
                }
                base.TopMost = true;
            }
            if ((((e.Alt && (e.KeyCode > Keys.Sleep)) && (e.KeyCode < Keys.Multiply)) || ((e.KeyCode == Keys.Divide) || (e.KeyCode == Keys.Multiply))) || (e.KeyCode == Keys.Subtract))
            {
                switch (e.KeyCode)
                {
                    case Keys.NumPad0:
                        this.CalcToggleView(ToggleView.none);
                        return;

                    case Keys.NumPad1:
                        this.CalcToggleView(ToggleView.players);
                        return;

                    case Keys.NumPad2:
                        this.CalcToggleView(ToggleView.alliedunits);
                        return;

                    case Keys.NumPad3:
                        this.CalcToggleView(ToggleView.enemyplayersflaged);
                        return;

                    case Keys.NumPad4:
                        this.CalcToggleView(ToggleView.enemyplayersunflaged);
                        return;

                    case Keys.NumPad5:
                        this.CalcToggleView(ToggleView.questobjects);
                        return;

                    case Keys.NumPad6:
                        this.CalcToggleView(ToggleView.miniralobject);
                        return;

                    case Keys.NumPad7:
                        this.CalcToggleView(ToggleView.bushobjects);
                        return;

                    case Keys.NumPad8:
                        this.CalcToggleView(ToggleView.treasureobjects);
                        return;

                    case Keys.NumPad9:
                        this.CalcToggleView(ToggleView.fishobjects);
                        return;

                    case Keys.Multiply:
                        this.CalcToggleView(ToggleView.unitsneutral);
                        return;

                    case Keys.Add:
                    case Keys.Separator:
                    case Keys.Decimal:
                        return;

                    case Keys.Subtract:
                        this.CalcToggleView(ToggleView.unitenemy);
                        return;

                    case Keys.Divide:
                        this.CalcToggleView(ToggleView.unitsfreindly);
                        return;
                }
            }
            else if (e.Alt && (e.KeyCode == Keys.Add))
            {
                MessageBox.Show((((((("Toggle Help: \r\n" + "NumPad0: none \r\n") + "NumPad1: players \r\n" + "NumPad2: allied units \r\n") + "NumPad3: enemy players flagged \r\n" + "NumPad4: enemy players unflaged \r\n") + "NumPad5: quest objects \r\n" + "NumPad6: miniral object \r\n") + "NumPad7: bush objects \r\n" + "NumPad8: treasure objects \r\n") + "NumPad9: fish objects \r\n" + "Divide: units freindly \r\n") + "Multiply: units neutral \r\n" + "Subtract: unit enemy \r\n");
            }
        }

        private void frmMain_KeyUp(object sender, KeyEventArgs e)
        {
            ViewMain main;
            if (e.KeyCode == Keys.F6)
            {
                this.hideName = !this.hideName;
            }
            if (e.KeyCode == Keys.Escape)
            {
                base.Close();
            }
            if (e.KeyCode == Keys.F11)
            {
                StreamWriter writer = new StreamWriter(@".\logit.log");
                lock ((main = this.mSender))
                {
                    writer.WriteLine(DateTime.Now.ToString() + "---------------------");
                    writer.WriteLine("channel " + this.mSender.Player.channel.ToString() + "\t" + this.mSender.GetObjectName(this.mSender.Player.channel));
                    writer.WriteLine("summon " + this.mSender.Player.summon.ToString() + "\t" + this.mSender.GetObjectName(this.mSender.Player.summon));
                    writer.WriteLine("target " + this.mSender.Player.target.ToString() + "\t" + this.mSender.GetObjectName(this.mSender.Player.target));
                    writer.WriteLine("charm " + this.mSender.Player.charm.ToString() + "\t" + this.mSender.GetObjectName(this.mSender.Player.charm));
                    writer.WriteLine("------------------------------------------------");
                }
            }
            if (e.KeyCode == Keys.F10)
            {
                if (!this.mHasStarted)
                {
                    this.tbInstructions.Visible = false;
                    try
                    {
                        Globals.Updating = false;
                        this.ConnectClient();
                        this.BuildAreas();
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message, "Unable to start");
                        this.Text = "";
                        this.tbInstructions.Visible = true;
                    }
                }
                else
                {
                    this.Text = "";
                    this.Text = "";
                    this.tbInstructions.Visible = true;
                    base.FormBorderStyle = FormBorderStyle.SizableToolWindow;
                }
            }
            if (e.KeyCode == Keys.F2)
            {
                this.scale *= 0.9f;
            }
            if (e.KeyCode == Keys.F3)
            {
                this.scale *= 1.1f;
            }
            if (e.KeyCode == Keys.F1)
            {
                base.TopMost = false;
                frmOptions options = new frmOptions();
                lock ((main = this.mSender))
                {
                    long mFocusGuid = this.mFocusGuid;
                    if (options.View(this.settings, this.mSender, ref mFocusGuid) == DialogResult.OK)
                    {
                        this.mFocusGuid = mFocusGuid;
                        options.SaveSettings(this.settings);
                        this.settings.UpdateHashtable();
                    }
                }
                base.TopMost = this.settings.StayOnTop;
            }
            if (e.KeyCode == Keys.F12)
            {
                base.TopMost = false;
                frmFilters filters = new frmFilters();
                lock ((main = this.mSender))
                {
                    filters.View(this.mSender);
                }
                base.TopMost = this.settings.StayOnTop;
            }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            this.settings = new clsSettings();
            this.settings.LoadDefaults();
            if (File.Exists("SERFLITEMAX20.Viewer.xml"))
            {
                try
                {
                    XmlTextReader xmlReader = new XmlTextReader("SERFLITEMAX20.Viewer.xml");
                    XmlSerializer serializer = new XmlSerializer(this.settings.GetType());
                    this.settings = (clsSettings)serializer.Deserialize(xmlReader);
                    xmlReader.Close();
                }
                catch
                {
                    this.settings = new clsSettings();
                    this.settings.LoadDefaults();
                }
            }
            this.settings.UpdateHashtable();
            base.TopMost = this.settings.StayOnTop;
            Globals.Filter = this.settings.Filter;
        }

        private void frmRadar_FormClosing(object sender, FormClosingEventArgs e)
        {
            Support.SaveFilterObjectList();
        }

        private void GetDynamiDisplayData(ViewObjectContext context)
        {
            context.rotate = true;
            context.vBuffer = this.vbPlayer;
            context.noVertexs = 2;
            context.di = this.settings.GetDisplayItem("[Object: Dynamic]", null);
            context.visible = true;
        }

        private void GetGameObjectDisplayData(ViewObjectContext context)
        {
            context.visible = true;
            if (context.obj.nodeType == enNodeType.Mine)
            {
                context.vBuffer = this.vbMine;
                context.noVertexs = 5;
                context.di = this.settings.GetDisplayItem("[Object: Metal Ore]", null);
            }
            else if (context.obj.nodeType == enNodeType.Herb)
            {
                context.vBuffer = this.vbWeed;
                context.noVertexs = 4;
                context.di = this.settings.GetDisplayItem("[Object: Weed]", null);
            }
            else if (context.obj.nodeType == enNodeType.Chest)
            {
                context.vBuffer = this.vbMine;
                context.noVertexs = 5;
                context.di = this.settings.GetDisplayItem("[Object: Treasure]", null);
            }
            else if (context.obj.nodeType == enNodeType.Fish)
            {
                context.vBuffer = this.vbWeed;
                context.noVertexs = 4;
                context.di = this.settings.GetDisplayItem("[Object: Fish]", null);
            }
            else
            {
                context.vBuffer = this.vbObject;
                context.noVertexs = 2;
                context.di = this.settings.GetDisplayItem("[Object: Other]", null);
            }
        }

        private string GetMapName(int id)
        {
            string str = "";
            int num = id;
            if (num <= 230)
            {
                if (num <= 90)
                {
                    if (num <= 13)
                    {
                        switch (num)
                        {
                            case 0:
                                return "Azeroth";

                            case 1:
                                return "Kalimdor";

                            case 13:
                                return "test";
                        }
                        return str;
                    }
                    switch (num)
                    {
                        case 0x19:
                            return "ScottTest";

                        case 0x1a:
                        case 0x1b:
                        case 0x1c:
                        case 0x1f:
                        case 0x20:
                        case 0x26:
                        case 0x27:
                        case 40:
                        case 0x29:
                        case 0x2d:
                        case 0x2e:
                            return str;

                        case 0x1d:
                            return "Test";

                        case 30:
                            return "PVPZone01";

                        case 0x21:
                            return "Shadowfang";

                        case 0x22:
                            return "StormwindJail";

                        case 0x23:
                            return "StormwindPrison";

                        case 0x24:
                            return "DeadminesInstance";

                        case 0x25:
                            return "PVPZone02";

                        case 0x2a:
                            return "Collin";

                        case 0x2b:
                            return "WailingCaverns";

                        case 0x2c:
                            return "Monastery";

                        case 0x2f:
                            return "RazorfenKraulInstance";

                        case 0x30:
                            return "Blackfathom";

                        case 70:
                            return "Uldaman";

                        case 90:
                            return "GnomeragonInstance";
                    }
                    return str;
                }
                if (num <= 0xa9)
                {
                    switch (num)
                    {
                        case 0x6d:
                            return "SunkenTemple";

                        case 0x81:
                            return "RazorfenDowns";

                        case 0xa9:
                            return "EmeraldDream";
                    }
                    return str;
                }
                switch (num)
                {
                    case 0xe5:
                        return "BlackRockSpire";

                    case 230:
                        return "BlackrockDepths";

                    case 0xd1:
                        return "TanarisInstance";

                    case 0xbd:
                        return "MonasteryInstances";
                }
                return str;
            }
            if (num <= 0x15d)
            {
                if (num <= 0x121)
                {
                    switch (num)
                    {
                        case 0xf9:
                            return "OnyxiaLairInstance";

                        case 0x10d:
                            return "CavernsOfTime";

                        case 0x121:
                            return "SchoolofNecromancy";
                    }
                    return str;
                }
                switch (num)
                {
                    case 0x135:
                        return "Zul'gurub";

                    case 0x149:
                        return "Stratholme";

                    case 0x15d:
                        return "Mauradon";
                }
                return str;
            }
            if (num <= 0x199)
            {
                switch (num)
                {
                    case 0x171:
                        return "DeeprunTram";

                    case 0x185:
                        return "OrgrimmarInstance";

                    case 0x199:
                        return "MoltenCore";
                }
                return str;
            }
            switch (num)
            {
                case 0x1c1:
                    return "AlliancePVPBarracks";

                case 450:
                    return "HordePVPBarracks";

                case 0x1c3:
                    return "development";

                case 0x1ad:
                    return "DireMaul";

                case 0x1d5:
                    return "BlackwingLair";

                case 470:
                case 0x1d7:
                case 0x1d8:
                case 0x1d9:
                case 0x1da:
                case 0x1db:
                case 0x1dc:
                case 0x1dd:
                case 0x1de:
                case 0x1df:
                case 480:
                case 0x1e1:
                case 0x1e2:
                case 0x1e3:
                case 0x1e4:
                case 0x1e5:
                case 0x1e6:
                case 0x1e7:
                case 0x1e8:
                case 490:
                case 0x1eb:
                case 0x1ec:
                case 0x1ed:
                case 0x1ee:
                case 0x1ef:
                case 0x1f0:
                case 0x1f1:
                case 0x1f2:
                case 0x1f3:
                case 500:
                case 0x1f5:
                case 0x1f6:
                case 0x1f7:
                case 0x1f8:
                case 0x1f9:
                case 0x1fa:
                case 0x1fb:
                case 0x1fc:
                case 510:
                case 0x1ff:
                case 0x200:
                case 0x201:
                case 0x202:
                case 0x203:
                case 0x204:
                case 0x205:
                case 0x206:
                case 0x207:
                case 520:
                case 0x209:
                case 0x20a:
                case 0x20b:
                case 0x20c:
                case 0x20d:
                case 0x20e:
                case 0x20f:
                case 0x210:
                case 0x217:
                case 0x218:
                case 0x219:
                case 0x21a:
                case 0x21b:
                case 0x21d:
                case 0x225:
                case 0x227:
                case 0x231:
                case 0x233:
                case 0x237:
                case 0x239:
                case 570:
                case 0x241:
                case 0x243:
                case 0x245:
                case 0x247:
                case 0x263:
                    return str;

                case 0x1e9:
                    return "PVPZone03";

                case 0x1fd:
                    return "AhnQiraj";

                case 0x211:
                    return "PVPZone04";

                case 530:
                    return "Expansion01";

                case 0x213:
                    return "AhnQirajTemple";

                case 0x214:
                    return "Karazahn";

                case 0x215:
                    return "Stratholme Raid";

                case 0x216:
                    return "HyjalPast";

                case 540:
                    return "HellfireMilitary";

                case 0x21e:
                    return "HellfireDemon";

                case 0x21f:
                    return "HellfireRampart";

                case 0x220:
                    return "HellfireRaid";

                case 0x221:
                    return "CoilfangPumping";

                case 0x222:
                    return "CoilfangMarsh";

                case 0x223:
                    return "CoilfangDraenei";

                case 0x224:
                    return "CoilfangRaid";

                case 550:
                    return "TempestKeepRaid";

                case 0x228:
                    return "TempestKeepArcane";

                case 0x229:
                    return "TempestKeepAtrium";

                case 0x22a:
                    return "TempestKeepFactory";

                case 0x22b:
                    return "AuchindounShadow";

                case 0x22c:
                    return "AuchindounDemon";

                case 0x22d:
                    return "AuchindounEthereal";

                case 0x22e:
                    return "AuchindounDraenei";

                case 0x22f:
                    return "PVPZone05";

                case 560:
                    return "HillsbradPast";

                case 0x232:
                    return "bladesedgearena";

                case 0x234:
                    return "BlackTemple";

                case 0x235:
                    return "GruulsLair";

                case 0x236:
                    return "NetherstormBG";

                case 0x238:
                    return "ZulAman";

                case 0x23b:
                    return "Northrend";

                case 0x23c:
                    return "PVPLordaeron";

                case 0x23d:
                    return "ExteriorTest";

                case 0x23e:
                    return "Valgarde70";

                case 0x23f:
                    return "UtgardePinnacle";

                case 0x240:
                    return "Nexus70";

                case 0x242:
                    return "Nexus80";

                case 580:
                    return "SunwellPlateau";

                case 0x246:
                    return "Transport176244";

                case 0x248:
                    return "Transport176231";

                case 0x249:
                    return "Sunwell5ManFix";

                case 0x24a:
                    return "Transport181645";

                case 0x24b:
                    return "Transport177233";

                case 0x24c:
                    return "Transport176310";

                case 0x24d:
                    return "Transport175080";

                case 590:
                    return "Transport176495";

                case 0x24f:
                    return "Transport164871";

                case 0x250:
                    return "Transport186238";

                case 0x251:
                    return "Transport20808";

                case 0x252:
                    return "Transport187038";

                case 0x253:
                    return "StratholmeCOT";

                case 0x254:
                    return "Transport187263";

                case 0x255:
                    return "CraigTest";

                case 0x256:
                    return "Sunwell5Man";

                case 0x257:
                    return "Ulduar70";

                case 600:
                    return "DrakTheronKeep";

                case 0x259:
                    return "Azjol_Uppercity";

                case 0x25a:
                    return "Ulduar80";

                case 0x25b:
                    return "UlduarRaid";

                case 0x25c:
                    return "GunDrak";

                case 0x25d:
                    return "development_nonweighted";

                case 0x25e:
                    return "QA_DVD";

                case 0x25f:
                    return "NorthrendBG";

                case 0x260:
                    return "DalaranPrison";

                case 0x261:
                    return "DeathKnightStart";

                case 610:
                    return "Transport_Tirisfal _Vengeance_Landing";

                case 0x264:
                    return "Transport_Menethil_Valgarde";

                case 0x265:
                    return "Transport_Orgrimmar_Warsong_Hold";

                case 0x266:
                    return "Transport_Stormwind_Valiance_Keep";

                case 0x267:
                    return "ChamberOfAspectsBlack";

                case 0x268:
                    return "NexusRaid";

                case 0x269:
                    return "DalaranArena";

                case 0x26a:
                    return "OrgrimmarArena";

                case 0x26b:
                    return "Azjol_LowerCity";

                case 620:
                    return "Transport_Moa'ki_Unu'pe";

                case 0x26d:
                    return "Transport_Moa'ki_Kamagua";

                case 0x26e:
                    return "Transport192241";

                case 0x26f:
                    return "Transport192242";

                case 0x270:
                    return "WintergraspRaid";
            }
            return str;
        }

        private void GetMinimapTexture(clsMinimap minimap)
        {
            int hMPQ = 0;
            int hFile = 0;
            int lpFileSizeHigh = 0;
            int lpNumberOfBytesRead = 0;
            if (SFmpq.SFileOpenArchive(@".\minimap.MPQ", 0, 0, ref hMPQ) == 1)
            {
                if (SFmpq.SFileOpenFileEx(hMPQ, minimap.filename, 0, ref hFile) != 1)
                {
                    SFmpq.SFileCloseFile(hMPQ);
                }
                else
                {
                    lpFileSizeHigh = SFmpq.SFileGetFileSize(hFile, ref lpFileSizeHigh);
                    byte[] lpBuffer = new byte[lpFileSizeHigh];
                    if (SFmpq.SFileReadFile(hFile, lpBuffer, (uint)lpFileSizeHigh, ref lpNumberOfBytesRead, IntPtr.Zero) == 1)
                    {
                        minimap.dxt1 = true;
                        MemoryStream stream = BLP2Parse.BLPtoDXT1(lpBuffer);
                        if ((stream != null) && (stream.Length > 0x70L))
                        {
                            stream.Seek(0L, SeekOrigin.Begin);
                            try
                            {
                                minimap.texture = TextureLoader.FromStream(this.device, stream);
                                if (minimap.texture == null)
                                {
                                    minimap.dxt1 = false;
                                }
                            }
                            catch
                            {
                                minimap.dxt1 = false;
                            }
                        }
                        if (!minimap.dxt1)
                        {
                            stream = BLP2Parse.BLPtoTGA(lpBuffer);
                            stream.Seek(0L, SeekOrigin.Begin);
                            try
                            {
                                minimap.texture = TextureLoader.FromStream(this.device, stream);
                            }
                            catch
                            {
                            }
                        }
                    }
                    SFmpq.SFileCloseFile(hFile);
                    SFmpq.SFileCloseArchive(hMPQ);
                }
            }
        }

        private void GetPlayerDisplayData(ViewObjectContext context)
        {
            context.rotate = true;
            context.vBuffer = this.vbPlayer;
            context.noVertexs = 2;
            context.di = this.settings.GetDisplayItem("[Player]", null);
            context.name = string.Format("{0} ({1})", context.obj.name, context.obj.level);
            context.visible = this.IsToggleView(ToggleView.alliedunits);
            if (context.obj.isDead)
            {
                context.di = this.settings.GetDisplayItem("[Players: Dead]", null);
            }
            else if ((context.obj.unitReaction == 1) && ((context.obj.flags & 0x200) > 0))
            {
                context.di = this.settings.GetDisplayItem("[Players: Agressive]", context.di);
                context.visible = this.IsToggleView(ToggleView.enemyplayersflaged);
            }
            else if (context.obj.unitReaction == 1)
            {
                context.visible = this.IsToggleView(ToggleView.enemyplayersunflaged);
                context.di = this.settings.GetDisplayItem("[Players: Neutral]", context.di);
            }
        }

        private void GetUnitDisplayData(ViewObjectContext context)
        {
            context.visible = true;
            context.rotate = true;
            context.vBuffer = this.vbMonster;
            context.noVertexs = 1;
            context.name = string.Format("{0} ({1})", context.obj.name, context.obj.level);
            if (context.obj.isDead)
            {
                context.di = this.settings.GetDisplayItem("[NPC's: Dead]", null);
            }
            else
            {
                switch (context.obj.unitReaction)
                {
                    case 1:
                        context.visible = this.IsToggleView(ToggleView.unitenemy);
                        context.di = this.settings.GetDisplayItem("[NPC's: Agressive]", null);
                        return;

                    case 2:
                        return;

                    case 3:
                        context.visible = this.IsToggleView(ToggleView.unitsneutral);
                        context.di = this.settings.GetDisplayItem("[NPC's: Neutral]", null);
                        return;

                    case 4:
                        context.visible = this.IsToggleView(ToggleView.unitsfreindly);
                        context.di = this.settings.GetDisplayItem("[NPC's: Friendly]", null);
                        return;
                }
            }
        }

        private void InitializeComponent()
        {
            this.tbInstructions = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // tbInstructions
            // 
            this.tbInstructions.BackColor = System.Drawing.Color.Black;
            this.tbInstructions.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.tbInstructions.Enabled = false;
            this.tbInstructions.ForeColor = System.Drawing.Color.White;
            this.tbInstructions.Location = new System.Drawing.Point(8, 8);
            this.tbInstructions.Multiline = true;
            this.tbInstructions.Name = "tbInstructions";
            this.tbInstructions.ReadOnly = true;
            this.tbInstructions.Size = new System.Drawing.Size(160, 88);
            this.tbInstructions.TabIndex = 3;
            this.tbInstructions.Text = "Press ESC to Quit\r\n\r\nPress F1 for Options\r\nPress F2 to Zoom Out\r\nPress F3 to Zoom" +
                " In\r\nPress F10 to Start / Stop\r\n\r\nYou can only resize this window if SERFLITEMAX" +
                "20.Viewer is not running.";
            // 
            // frmRadar
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.BackColor = System.Drawing.Color.Black;
            this.ClientSize = new System.Drawing.Size(633, 568);
            this.Controls.Add(this.tbInstructions);
            this.KeyPreview = true;
            this.Name = "frmRadar";
            this.Load += new System.EventHandler(this.frmMain_Load);
            this.DoubleClick += new System.EventHandler(this.frmMain_DoubleClick);
            this.Closing += new System.ComponentModel.CancelEventHandler(this.frmMain_Closing);
            this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.frmMain_KeyUp);
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmRadar_FormClosing);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.frmMain_KeyDown);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        public bool InitializeGraphics()
        {
            try
            {
                PresentParameters parameters = new PresentParameters();
                parameters.Windowed = true;
                parameters.SwapEffect = SwapEffect.Discard;
                this.device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, new PresentParameters[] { parameters });
                this.device.DeviceReset += new EventHandler(this.OnResetDevice);
                this.OnCreateDevice(this.device, null);
                this.OnResetDevice(this.device, null);
                this.font = new Microsoft.DirectX.Direct3D.Font(this.device, new System.Drawing.Font("arial", 8f));
                return true;
            }
            catch (DirectXException)
            {
                return false;
            }
        }

        private bool IsToggleView(ToggleView pToggleView)
        {
            return ((this.toggleViewMask & (int)pToggleView) > 0);
        }

        private clsMinimap LoadMinimap(int pX, int pY, string pMap)
        {
            if ((((pX > 0x3f) || (pY > 0x3f)) || (pX < 0)) || (pY < 0))
            {
                return null;
            }
            clsArea area = (clsArea)this.areas[pMap];
            if (area == null)
            {
                return null;
            }
            clsMinimap minimap = area.minimaps[pX, pY];
            if ((minimap != null) && (minimap.texture == null))
            {
                this.GetMinimapTexture(minimap);
            }
            return minimap;
        }

        public void OnCreateDevice(object sender, EventArgs e)
        {
            Device device = (Device)sender;
            this.vbMonster = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, device, Usage.None, VertexFormats.Diffuse | VertexFormats.Position, Pool.Default);
            this.vbMonster.Created += new EventHandler(this.OnCreateVBMonster);
            this.OnCreateVBMonster(this.vbMonster, null);
            this.vbPlayer = new VertexBuffer(typeof(CustomVertex.PositionColored), 6, device, Usage.None, VertexFormats.Diffuse | VertexFormats.Position, Pool.Default);
            this.vbPlayer.Created += new EventHandler(this.OnCreateVBPlayer);
            this.OnCreateVBPlayer(this.vbPlayer, null);
            this.vbWeed = new VertexBuffer(typeof(CustomVertex.PositionColored), 12, device, Usage.None, VertexFormats.Diffuse | VertexFormats.Position, Pool.Default);
            this.vbWeed.Created += new EventHandler(this.OnCreateVBWeed);
            this.OnCreateVBWeed(this.vbWeed, null);
            this.vbMine = new VertexBuffer(typeof(CustomVertex.PositionColored), 15, device, Usage.None, VertexFormats.Diffuse | VertexFormats.Position, Pool.Default);
            this.vbMine.Created += new EventHandler(this.OnCreateVBMine);
            this.OnCreateVBMine(this.vbMine, null);
            this.vbObject = new VertexBuffer(typeof(CustomVertex.PositionColored), 6, device, Usage.None, VertexFormats.Diffuse | VertexFormats.Position, Pool.Default);
            this.vbObject.Created += new EventHandler(this.OnCreateVBObject);
            this.OnCreateVBObject(this.vbObject, null);
            this.vbMinimap = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 6, device, Usage.None, VertexFormats.Texture1 | VertexFormats.PositionNormal, Pool.Default);
            this.vbMinimap.Created += new EventHandler(this.OnCreateVBMinimap);
            this.OnCreateVBMinimap(this.vbMinimap, null);
        }

        public void OnCreateVBMine(object sender, EventArgs e)
        {
            VertexBuffer buffer = (VertexBuffer)sender;
            CustomVertex.PositionColored[] coloredArray = (CustomVertex.PositionColored[])buffer.Lock(0, LockFlags.None);
            coloredArray[0].X = -2f;
            coloredArray[0].Y = 0f;
            coloredArray[0].Z = 0f;
            coloredArray[0].Color = Color.White.ToArgb();
            coloredArray[1].X = -2f;
            coloredArray[1].Y = 1f;
            coloredArray[1].Z = 0f;
            coloredArray[1].Color = Color.White.ToArgb();
            coloredArray[2].X = 0f;
            coloredArray[2].Y = 0f;
            coloredArray[2].Z = 0f;
            coloredArray[2].Color = Color.White.ToArgb();
            coloredArray[3].X = 2f;
            coloredArray[3].Y = 0f;
            coloredArray[3].Z = 0f;
            coloredArray[3].Color = Color.White.ToArgb();
            coloredArray[4].X = 2f;
            coloredArray[4].Y = 1f;
            coloredArray[4].Z = 0f;
            coloredArray[4].Color = Color.White.ToArgb();
            coloredArray[5].X = 0f;
            coloredArray[5].Y = 0f;
            coloredArray[5].Z = 0f;
            coloredArray[5].Color = Color.White.ToArgb();
            coloredArray[6].X = 2f;
            coloredArray[6].Y = 1f;
            coloredArray[6].Z = 0f;
            coloredArray[6].Color = Color.White.ToArgb();
            coloredArray[7].X = 1f;
            coloredArray[7].Y = 2f;
            coloredArray[7].Z = 0f;
            coloredArray[7].Color = Color.White.ToArgb();
            coloredArray[8].X = 0f;
            coloredArray[8].Y = 0f;
            coloredArray[8].Z = 0f;
            coloredArray[8].Color = Color.White.ToArgb();
            coloredArray[9].X = -2f;
            coloredArray[9].Y = 1f;
            coloredArray[9].Z = 0f;
            coloredArray[9].Color = Color.White.ToArgb();
            coloredArray[10].X = -1f;
            coloredArray[10].Y = 2f;
            coloredArray[10].Z = 0f;
            coloredArray[10].Color = Color.White.ToArgb();
            coloredArray[11].X = 0f;
            coloredArray[11].Y = 0f;
            coloredArray[11].Z = 0f;
            coloredArray[11].Color = Color.White.ToArgb();
            coloredArray[12].X = -1f;
            coloredArray[12].Y = 2f;
            coloredArray[12].Z = 0f;
            coloredArray[12].Color = Color.White.ToArgb();
            coloredArray[13].X = 1f;
            coloredArray[13].Y = 2f;
            coloredArray[13].Z = 0f;
            coloredArray[13].Color = Color.White.ToArgb();
            coloredArray[14].X = 0f;
            coloredArray[14].Y = 0f;
            coloredArray[14].Z = 0f;
            coloredArray[14].Color = Color.White.ToArgb();
            buffer.Unlock();
        }

        public void OnCreateVBMinimap(object sender, EventArgs e)
        {
            VertexBuffer buffer = (VertexBuffer)sender;
            CustomVertex.PositionNormalTextured[] texturedArray = (CustomVertex.PositionNormalTextured[])buffer.Lock(0, LockFlags.None);
            Microsoft.DirectX.Vector3 vector = new Microsoft.DirectX.Vector3(-(this.tileSize / 2f), -(this.tileSize / 2f), 0f);
            Microsoft.DirectX.Vector3 vector2 = new Microsoft.DirectX.Vector3(this.tileSize / 2f, -(this.tileSize / 2f), 0f);
            Microsoft.DirectX.Vector3 vector3 = new Microsoft.DirectX.Vector3(-(this.tileSize / 2f), this.tileSize / 2f, 0f);
            Microsoft.DirectX.Vector3 nor = this.ComputeNormal(vector, vector2, vector3);
            texturedArray[0] = new CustomVertex.PositionNormalTextured(vector, nor, 0f, 0f);
            texturedArray[1] = new CustomVertex.PositionNormalTextured(vector2, nor, 1f, 0f);
            texturedArray[2] = new CustomVertex.PositionNormalTextured(vector3, nor, 0f, 1f);
            vector = new Microsoft.DirectX.Vector3(this.tileSize / 2f, this.tileSize / 2f, 0f);
            vector2 = new Microsoft.DirectX.Vector3(-(this.tileSize / 2f), this.tileSize / 2f, 0f);
            vector3 = new Microsoft.DirectX.Vector3(this.tileSize / 2f, -(this.tileSize / 2f), 0f);
            nor = this.ComputeNormal(vector, vector2, vector3);
            texturedArray[3] = new CustomVertex.PositionNormalTextured(vector, nor, 1f, 1f);
            texturedArray[4] = new CustomVertex.PositionNormalTextured(vector2, nor, 0f, 1f);
            texturedArray[5] = new CustomVertex.PositionNormalTextured(vector3, nor, 1f, 0f);
            buffer.Unlock();
        }

        public void OnCreateVBMonster(object sender, EventArgs e)
        {
            VertexBuffer buffer = (VertexBuffer)sender;
            CustomVertex.PositionColored[] coloredArray = (CustomVertex.PositionColored[])buffer.Lock(0, LockFlags.None);
            coloredArray[0].X = -1f;
            coloredArray[0].Y = -2f;
            coloredArray[0].Z = 0f;
            coloredArray[0].Color = Color.White.ToArgb();
            coloredArray[1].X = 1f;
            coloredArray[1].Y = -2f;
            coloredArray[1].Z = 0f;
            coloredArray[1].Color = Color.White.ToArgb();
            coloredArray[2].X = 0f;
            coloredArray[2].Y = 2f;
            coloredArray[2].Z = 0f;
            coloredArray[2].Color = Color.White.ToArgb();
            buffer.Unlock();
        }

        public void OnCreateVBObject(object sender, EventArgs e)
        {
            VertexBuffer buffer = (VertexBuffer)sender;
            CustomVertex.PositionColored[] coloredArray = (CustomVertex.PositionColored[])buffer.Lock(0, LockFlags.None);
            coloredArray[0].X = -1f;
            coloredArray[0].Y = -1f;
            coloredArray[0].Z = 0f;
            coloredArray[0].Color = Color.White.ToArgb();
            coloredArray[1].X = 1f;
            coloredArray[1].Y = -1f;
            coloredArray[1].Z = 0f;
            coloredArray[1].Color = Color.White.ToArgb();
            coloredArray[2].X = -1f;
            coloredArray[2].Y = 1f;
            coloredArray[2].Z = 0f;
            coloredArray[2].Color = Color.White.ToArgb();
            coloredArray[3].X = 1f;
            coloredArray[3].Y = 1f;
            coloredArray[3].Z = 0f;
            coloredArray[3].Color = Color.White.ToArgb();
            coloredArray[4].X = 1f;
            coloredArray[4].Y = -1f;
            coloredArray[4].Z = 0f;
            coloredArray[4].Color = Color.White.ToArgb();
            coloredArray[5].X = -1f;
            coloredArray[5].Y = 1f;
            coloredArray[5].Z = 0f;
            coloredArray[5].Color = Color.White.ToArgb();
            buffer.Unlock();
        }

        public void OnCreateVBPlayer(object sender, EventArgs e)
        {
            VertexBuffer buffer = (VertexBuffer)sender;
            CustomVertex.PositionColored[] coloredArray = (CustomVertex.PositionColored[])buffer.Lock(0, LockFlags.None);
            coloredArray[0].X = -2f;
            coloredArray[0].Y = -2f;
            coloredArray[0].Z = 0f;
            coloredArray[0].Color = Color.White.ToArgb();
            coloredArray[1].X = 0f;
            coloredArray[1].Y = -1f;
            coloredArray[1].Z = 0f;
            coloredArray[1].Color = Color.White.ToArgb();
            coloredArray[2].X = 0f;
            coloredArray[2].Y = 2f;
            coloredArray[2].Z = 0f;
            coloredArray[2].Color = Color.White.ToArgb();
            coloredArray[3].X = 2f;
            coloredArray[3].Y = -2f;
            coloredArray[3].Z = 0f;
            coloredArray[3].Color = Color.White.ToArgb();
            coloredArray[4].X = 0f;
            coloredArray[4].Y = -1f;
            coloredArray[4].Z = 0f;
            coloredArray[4].Color = Color.White.ToArgb();
            coloredArray[5].X = 0f;
            coloredArray[5].Y = 2f;
            coloredArray[5].Z = 0f;
            coloredArray[5].Color = Color.White.ToArgb();
            buffer.Unlock();
        }

        public void OnCreateVBWeed(object sender, EventArgs e)
        {
            VertexBuffer buffer = (VertexBuffer)sender;
            CustomVertex.PositionColored[] coloredArray = (CustomVertex.PositionColored[])buffer.Lock(0, LockFlags.None);
            coloredArray[0].X = 0f;
            coloredArray[0].Y = 2f;
            coloredArray[0].Z = 0f;
            coloredArray[0].Color = Color.White.ToArgb();
            coloredArray[1].X = -1f;
            coloredArray[1].Y = 0f;
            coloredArray[1].Z = 0f;
            coloredArray[1].Color = Color.White.ToArgb();
            coloredArray[2].X = 1f;
            coloredArray[2].Y = 0f;
            coloredArray[2].Z = 0f;
            coloredArray[2].Color = Color.White.ToArgb();
            coloredArray[3].X = 0f;
            coloredArray[3].Y = -2f;
            coloredArray[3].Z = 0f;
            coloredArray[3].Color = Color.White.ToArgb();
            coloredArray[4].X = -1f;
            coloredArray[4].Y = 0f;
            coloredArray[4].Z = 0f;
            coloredArray[4].Color = Color.White.ToArgb();
            coloredArray[5].X = 1f;
            coloredArray[5].Y = 0f;
            coloredArray[5].Z = 0f;
            coloredArray[5].Color = Color.White.ToArgb();
            coloredArray[6].X = -2f;
            coloredArray[6].Y = 0f;
            coloredArray[6].Z = 0f;
            coloredArray[6].Color = Color.White.ToArgb();
            coloredArray[7].X = 0f;
            coloredArray[7].Y = 1f;
            coloredArray[7].Z = 0f;
            coloredArray[7].Color = Color.White.ToArgb();
            coloredArray[8].X = 0f;
            coloredArray[8].Y = -1f;
            coloredArray[8].Z = 0f;
            coloredArray[8].Color = Color.White.ToArgb();
            coloredArray[9].X = 2f;
            coloredArray[9].Y = 0f;
            coloredArray[9].Z = 0f;
            coloredArray[9].Color = Color.White.ToArgb();
            coloredArray[10].X = 0f;
            coloredArray[10].Y = 1f;
            coloredArray[10].Z = 0f;
            coloredArray[10].Color = Color.White.ToArgb();
            coloredArray[11].X = 0f;
            coloredArray[11].Y = -1f;
            coloredArray[11].Z = 0f;
            coloredArray[11].Color = Color.White.ToArgb();
            buffer.Unlock();
        }

        public void OnResetDevice(object sender, EventArgs e)
        {
            Device device = (Device)sender;
            device.RenderState.CullMode = Cull.None;
            device.RenderState.Lighting = false;
            device.RenderState.ZBufferEnable = true;
            device.RenderState.AntiAliasedLineEnable = true;
        }

        private void OnUpdate(string pInXml)
        {
            if (!Globals.Updating)
            {
                if (this.mThread != null)
                {
                    if (this.mThread.ThreadState == System.Threading.ThreadState.Running)
                    {
                        return;
                    }
                    if (this.mThread.ThreadState != System.Threading.ThreadState.Stopped)
                    {
                        try
                        {
                            this.mThread.Abort();
                        }
                        catch
                        {
                        }
                    }
                }
                this.mThread = new Thread(new ParameterizedThreadStart(this.ProcessReceivedXml));
                this.mThread.Start(pInXml);
            }
        }

        private void OnUpdateMain(ViewMain sender)
        {
            if (!Globals.Updating)
            {
                try
                {
                    Globals.Updating = true;
                    if (this.device == null)
                    {
                        return;
                    }
                    lock (this.device)
                    {
                        if (sender.Player == null)
                        {
                            return;
                        }
                        this.focusObject = sender.Player;
                        if (sender.Objects.ContainsKey(this.mFocusGuid))
                        {
                            this.focusObject = (ViewObject)sender.Objects[this.mFocusGuid];
                        }
                        this.device.Clear(ClearFlags.Target, Color.Black, 1f, 0);
                        float valueZ = 100000f;
                        Microsoft.DirectX.Vector3 cameraPosition = new Microsoft.DirectX.Vector3(0f, 0f, valueZ);
                        Microsoft.DirectX.Vector3 cameraTarget = new Microsoft.DirectX.Vector3(0f, 0f, 0f);
                        Microsoft.DirectX.Vector3 cameraUpVector = new Microsoft.DirectX.Vector3(0f, -1f, 0f);
                        Microsoft.DirectX.Matrix sourceMatrix = Microsoft.DirectX.Matrix.RotationY(3.141592f) * Microsoft.DirectX.Matrix.RotationX(3.141592f);
                        if (this.settings.RotateMap)
                        {
                            sourceMatrix *= Microsoft.DirectX.Matrix.RotationZ(6.283185f - this.focusObject.facing);
                        }
                        cameraPosition.TransformCoordinate(sourceMatrix);
                        cameraTarget.TransformCoordinate(sourceMatrix);
                        cameraUpVector.TransformCoordinate(sourceMatrix);
                        cameraTarget.Add(new Microsoft.DirectX.Vector3(this.focusObject.x, this.focusObject.y, this.focusObject.z));
                        cameraPosition.Add(new Microsoft.DirectX.Vector3(this.focusObject.x, this.focusObject.y, this.focusObject.z));
                        this.device.Transform.View = Microsoft.DirectX.Matrix.LookAtLH(cameraPosition, cameraTarget, cameraUpVector);
                        this.device.Transform.Projection = Microsoft.DirectX.Matrix.PerspectiveLH(((float)base.Width) / (valueZ * this.scale), ((float)base.Height) / (valueZ * this.scale), 1f, 1000000f);
                        this.device.BeginScene();
                        if (this.mbool && this.settings.ShowMinimap)
                        {
                            this.DrawMinimap();
                        }
                        foreach (ViewObject obj2 in sender.Objects.Values)
                        {
                            if (((((obj2.type == enObjectTypes.Container) || (obj2.type == enObjectTypes.Dynamic)) || ((obj2.type == enObjectTypes.Item) || (obj2.type == enObjectTypes.None))) || (obj2.type == enObjectTypes.Unknown)) || (!this.filterName.IsEmpty() && ((obj2.name != null) && (obj2.name.IndexOf(this.filterName) == -1))))
                            {
                                continue;
                            }
                            ViewObjectContext context2 = new ViewObjectContext();
                            context2.di = this.settings.GetDisplayItem("[Object: Other]", null);
                            context2.vBuffer = this.vbObject;
                            context2.name = obj2.name;
                            context2.obj = obj2;
                            ViewObjectContext context = context2;
                            switch (obj2.type)
                            {
                                case enObjectTypes.Unit:
                                    this.GetUnitDisplayData(context);
                                    break;

                                case enObjectTypes.Player:
                                    this.GetPlayerDisplayData(context);
                                    break;

                                case enObjectTypes.GameObject:
                                    if ((obj2.type == enObjectTypes.GameObject) && (obj2.typeid != GameobjectTypes.NONE))
                                    {
                                        this.GetGameObjectDisplayData(context);
                                    }
                                    break;
                            }
                            if (context.visible)
                            {
                                if (obj2.name != null)
                                {
                                    context.di = this.settings.GetDisplayItem(obj2.name.ToLower(), context.di);
                                }
                                if ((context.di != null) && context.di.Visible)
                                {
                                    int color = context.di.Color;
                                    if (obj2.special)
                                    {
                                        clsAlert alert = null;
                                        if (this.alertList.ContainsKey(obj2.guid))
                                        {
                                            alert = this.alertList[obj2.guid];
                                        }
                                        else
                                        {
                                            alert = new clsAlert();
                                            this.alertList.Add(obj2.guid, alert);
                                        }
                                        color = alert.CalcFlash(context.di.Color);
                                    }
                                    float x = 2f * (2f / this.scale);
                                    Microsoft.DirectX.Vector3 v = new Microsoft.DirectX.Vector3(obj2.x, obj2.y, obj2.z);
                                    this.device.Transform.World = Microsoft.DirectX.Matrix.Scaling(x, x, x);
                                    if (context.rotate)
                                    {
                                        Transforms transforms1 = this.device.Transform;
                                        transforms1.World *= Microsoft.DirectX.Matrix.RotationZ(6.283185f - obj2.facing);
                                    }
                                    else if (this.settings.RotateMap)
                                    {
                                        Transforms transforms2 = this.device.Transform;
                                        transforms2.World *= Microsoft.DirectX.Matrix.RotationZ(6.283185f - this.focusObject.facing);
                                    }
                                    Transforms transform = this.device.Transform;
                                    transform.World *= Microsoft.DirectX.Matrix.Translation(v);
                                    this.device.RenderState.TextureFactor = color;
                                    this.device.TextureState[0].ColorOperation = TextureOperation.Modulate;
                                    this.device.TextureState[0].ColorArgument0 = TextureArgument.TextureColor;
                                    this.device.TextureState[0].ColorArgument1 = TextureArgument.TFactor;
                                    this.device.VertexFormat = VertexFormats.Diffuse | VertexFormats.Position;
                                    this.device.SetTexture(0, null);
                                    this.device.SetStreamSource(0, context.vBuffer, 0);
                                    this.device.DrawPrimitives(PrimitiveType.TriangleList, 0, context.noVertexs);
                                    v = Microsoft.DirectX.Vector3.Project(new Microsoft.DirectX.Vector3(0f, 0f, 0f), this.device.Viewport, this.device.Transform.Projection, this.device.Transform.View, this.device.Transform.World);
                                    if (((context.name != null) && !this.hideName) && (context.di.DisplayText != eDisplayText.Nothing))
                                    {
                                        this.font.DrawText(null, context.name, (int)(((int)v.X) + 10), (int)(((int)v.Y) - 4), color);
                                    }
                                }
                            }
                        }
                        this.device.EndScene();
                        this.device.Present();
                        if (this.alertList.Count > 0)
                        {
                            Queue<long> queue = new Queue<long>();
                            foreach (long num4 in this.alertList.Keys)
                            {
                                if (!sender.Objects.ContainsKey(num4))
                                {
                                    queue.Enqueue(num4);
                                }
                            }
                            foreach (long num4 in queue)
                            {
                                this.alertList.Remove(num4);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                    try
                    {
                    }
                    catch
                    {
                        this.device.EndScene();
                    }
                }
            }
            Globals.Updating = false;
        }

        private void OnUpdateStatus(string status)
        {
            this.RunStatusForm();
            this.mFormStatus.UpdateStatus(status);
        }

        private void ProcessReceivedXml(object pInXml)
        {
            lock (this.mSender)
            {
                this.mSender.InitializeFromXML((string)pInXml);
                this.SetText(this.mSender.Title);
                this.OnUpdateMain(this.mSender);
            }
        }

        private void RunStatusForm()
        {
            if (base.InvokeRequired)
            {
                delRunStatusForm method = new delRunStatusForm(this.RunStatusForm);
                base.Invoke(method);
            }
            else if (this.mFormStatus == null)
            {
                this.mFormStatus = new frmStatus();
                this.mFormStatus.View();
            }
        }

        public void SetText(string text)
        {
            if (base.InvokeRequired)
            {
                base.Invoke(new DelSetText(this.SetText), new object[] { text });
            }
            else
            {
                this.Text = text;
                if (this.mSender.WoWActive != this.wowactive)
                {
                    this.wowactive = this.mSender.WoWActive;
                    if (!this.mSender.WoWActive)
                    {
                        this.previouseFormWindowState = base.WindowState;
                        base.WindowState = FormWindowState.Minimized;
                    }
                    else
                    {
                        base.WindowState = this.previouseFormWindowState;
                    }
                }
            }
        }

        private delegate void delRunStatusForm();

        private delegate void DelSetText(string text);

        private delegate void DelUpdateText();
    }
}

